package cn.nohan.funplay.module.member.mongo.service.notify;

import cn.nohan.funplay.module.member.mongo.service.notify.mapper.SystemMessageMapper;
import cn.nohan.funplay.module.member.mongo.service.notify.message.AbdicateMessage;
import cn.nohan.funplay.module.member.mongo.service.notify.message.ActivityInfo;
import cn.nohan.funplay.module.member.mongo.service.notify.message.Message;
import cn.nohan.funplay.module.member.mongo.service.notify.message.PaymentMessage;
import cn.nohan.funplay.module.member.mongo.service.notify.notify.MessageTitle;
import cn.nohan.funplay.module.member.mongo.service.notify.notify.SystemMessageTypeEnum;
import com.mongoplus.conditions.query.QueryWrapper;
import com.mongoplus.model.PageResult;
import org.bson.Document;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.math.BigDecimal;
import java.time.LocalDateTime;
import java.util.Date;

/**
 * @author caozhipeng
 * @date 2025/8/13
 */
@Service
public class SystemMessageServiceImpl implements SystemMessageService{

    @Autowired
    private SystemMessageMapper systemMessageMapper;

    @Override
    public void sendMessage(SystemMessage<PaymentMessage> systemMessage) {
        systemMessage.setCreateTime(LocalDateTime.now());
        systemMessage.setDeleted(false);
        systemMessage.setIsRead(false);
        systemMessageMapper.save(systemMessage);
    }

    @Override
    public void sendMessage() {
        PaymentMessage paymentMessage = new PaymentMessage();
        paymentMessage.setTitle("支付成功");
        paymentMessage.setContent("您的支付金额为100元，已成功支付");
        paymentMessage.setAmount( new BigDecimal("100.01"));
        paymentMessage.setPaymentChannel("支付宝");
        paymentMessage.setReflectTime(new Date());
        paymentMessage.setPaymentDate(new Date());


        SystemMessage<PaymentMessage> systemMessage=new SystemMessage<PaymentMessage>();
        systemMessage.setMessageType(SystemMessageTypeEnum.PAYMENT.getCode());
        systemMessage.setMessage(paymentMessage);
        systemMessage.setCreateTime(LocalDateTime.now());
        systemMessage.setDeleted(false);
        systemMessage.setIsRead(false);
        systemMessageMapper.save(systemMessage);
    }

    @Override
    public void sendMessage5() {
        ActivityInfo activityInfo=new ActivityInfo();
        activityInfo.setActivityAddress("无锡市南长街");
        activityInfo.setActivityTitle("打羽毛");
        activityInfo.setActivityContent("活动内容");
        activityInfo.setActivityImage("https://ts1.tc.mm.bing.net/th/id/R-C.32af73b7aea55367e4a3f8763961c894?rik=QUOZ37Lf%2bE7rbw&riu=http%3a%2f%2fimg95.699pic.com%2fphoto%2f50064%2f7148.jpg_wh860.jpg&ehk=00VUYvoTnuinFTJXQYbpLwh3e%2bLPJE9vL7h5ELm0avA%3d&risl=&pid=ImgRaw&r=0");
        activityInfo.setActivityStartTime(LocalDateTime.now());
        activityInfo.setActivityEndTime(new Date());
        activityInfo.setUserName("张三");
        activityInfo.setUserId(1L);
        activityInfo.setActivityId(1L);

        AbdicateMessage message = new AbdicateMessage();
        message.setActivityInfo(activityInfo);
        message.setTitle(MessageTitle.title19);
        message.setFromAbdicateUserName("张三");
        message.setToAbdicateUserName("李四");
        message.setAbdicateTime(new Date());


        SystemMessage<AbdicateMessage> systemMessage=new SystemMessage<AbdicateMessage>();
        systemMessage.setUserId(50L);
        systemMessage.setMessageType(SystemMessageTypeEnum.ACTIVITY_ABDICATE.getCode());
        systemMessage.setMessage(message);
        systemMessage.setCreateTime(LocalDateTime.now());
        systemMessage.setDeleted(false);
        systemMessage.setIsRead(false);
        systemMessageMapper.save(systemMessage);
    }


    public SystemMessage<? extends Message> getMessage(String id) {
        return systemMessageMapper.getById(id, SystemMessage.class);
    }

    @Override
    public Document getMessage2(String id) {
        return systemMessageMapper.getById(id, Document.class);
    }

    public SystemMessage getMessage3(String id) {
        return systemMessageMapper.getById(id, SystemMessage.class);
    }

    public PageResult<SystemMessage>  getMessagePage(Integer pageNo,Integer pageSize,Integer messageType){
        QueryWrapper<SystemMessage> queryWrapper=new QueryWrapper<SystemMessage>();
        queryWrapper.eq(messageType!=null,SystemMessage::getMessageType,messageType);
        PageResult<SystemMessage> messagePage=systemMessageMapper.page(queryWrapper,pageNo,pageSize);
        return messagePage;
    }

}
